//
//  LYMainTabbarView.swift
//  微博
//
//  Created by liuerying on 16/5/19.
//  Copyright © 2016年 liuerying. All rights reserved.
//

import UIKit

class LYMainTabbarView: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(plusBtn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        //不希望从xib加载的话,就默认在这个地方崩溃
        fatalError("init(coder:) has not been implemented")
    }
 
    override func layoutSubviews() {
        super.layoutSubviews()

        let width = self.bounds.width / 5
        let height = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: width, height: height)
        
        var index: CGFloat = 0
        for subView in subviews{
        
//            print(subviews)
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){
            
                 subView.frame = CGRectOffset(rect, index*width, 0)
                
//                if index == 1{
//                
//                    index += 1
//                }
//                
//                index += 1

            //三目运算
                index += (index == 1 ? 2 : 1)
            }
        
           
            
          
        
        }
        plusBtn.frame = CGRectOffset(rect, 2*width, 0)
    }
    
    
    lazy var plusBtn: UIButton = {
    
        let btn = UIButton()
       
        btn.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), forState: UIControlState.Normal)
         btn.setImage(UIImage(named:"tabbar_compose_icon_add"), forState: UIControlState.Selected)
        
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        
        
        
        return btn
    }()
    

}
